<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Hello, World</title>
    <link rel="stylesheet" href="js/layui/css/layui.css">
    <style type="text/css">
        html {
            height: 100%
        }
        
        body {
            height: 100%;
            margin: 0px;
            padding: 0px
        }
        
        .info {
            position: absolute;
            top: 12px;
            left: 80px;
        }
        
        #container {
            height: 100%
        }
    </style>

    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="js/layui/layui.js"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=23b2ad2ab42c26c69306e11e4522590f">
        //v2.0版本的引用方式：src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"
        //v1.4版本及以前版本的引用方式：src="http://api.map.baidu.com/api?v=1.4&key=您的密钥&callback=initialize"
    </script>
</head>

<body>
    <div id="container"></div>
    <div class="info">
        <form class="layui-form" action="">
            <input type="checkbox" name="" title="东城区">
            <input type="checkbox" name="" title="西城区">
            <input type="checkbox" name="" title="朝阳区">
            <input type="checkbox" name="" title="丰台区">
            <input type="checkbox" name="" title="石景山">
            <input type="checkbox" name="" title="海淀区">
            <input type="checkbox" name="" title="顺义区">
            <input type="checkbox" name="" title="通州区">
            <input type="checkbox" name="" title="大兴区">
            <input type="checkbox" name="" title="房山区">
            <input type="checkbox" name="" title="门头沟">
            <input type="checkbox" name="" title="昌平区">
            <input type="checkbox" name="" title="平谷区">
            <input type="checkbox" name="" title="密云区">
            <input type="checkbox" name="" title="怀柔区">
            <input type="checkbox" name="" title="延庆区">
        </form>
    </div>
    <script type="text/javascript">
        layui.use('form', function() {
            var form = layui.form;

            //监听提交
            form.on('checkbox', function(data) {
                layer.msg(JSON.stringify(data.field));
                return false;
            });
        });

        var map = new BMap.Map("container"); // 创建地图实例  
        var point = new BMap.Point(116.403784, 39.914991); // 创建点坐标  
        map.addControl(new BMap.NavigationControl());
        map.addControl(new BMap.ScaleControl());
        map.addControl(new BMap.OverviewMapControl());
        map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
        map.centerAndZoom(point, 10); // 初始化地图，设置中心点坐标和地图级别

        // 定义一个控件类,即function
        function ShowLocationControl() {
            // 默认停靠位置和偏移量
            this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
            this.defaultOffset = new BMap.Size(10, 10);
        }

        // 通过JavaScript的prototype属性继承于BMap.Control
        ShowLocationControl.prototype = new BMap.Control();

        // 自定义控件必须实现自己的initialize方法,并且将控件的DOM元素返回
        // 在本方法中创建个div元素作为控件的容器,并将其添加到地图容器中
        ShowLocationControl.prototype.initialize = function(map) {
                // 创建一个DOM元素
                var div = document.createElement("div");
                // 添加文字说明

                map.addEventListener("mousemove", function(e) {
                    var lon = e.point.lng;
                    var lat = e.point.lat;
                    div.innerHTML = lon + ";" + lat;
                });

                // 设置样式
                div.style.width = "195px";
                div.style.border = "1px solid gray";
                div.style.backgroundColor = "white";

                // 添加DOM元素到地图中
                map.getContainer().appendChild(div);
                // 将DOM元素返回
                return div;
            }
            // 创建控件
        var mylocationCtrl = new ShowLocationControl();
        // 添加到地图当中
        map.addControl(mylocationCtrl);

        $.getJSON('json/beijing.json', function(data) {
            var a = data,
                b = a.features[0].geometry,
                c = b.coordinates[0];
            var arr = [];
            for (var i = 0, len = c.length; i < len; i++) {
                var point = new BMap.Point(c[i][0], c[i][1]);
                arr.push(point);
            }
            var polygon = new BMap.Polygon(arr, {
                strokeColor: "#0064fc",
                fillColor: "#0064fc",
                strokeWeight: 2,
                fillOpacity: 0.2,
                strokeOpacity: 0.7,
                strokeStyle: 'solid'
            }); //创建多边形
            map.addOverlay(polygon); //增加多边形
        });
    </script>
</body>

</html>